/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/


#if !defined(AFX_PGLOBJECTREGISTRY_H__3EE4CCAA_FDBF_4B8C_934F_B8A25A7DD905__INCLUDED_)
#define AFX_PGLOBJECTREGISTRY_H__3EE4CCAA_FDBF_4B8C_934F_B8A25A7DD905__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class CPGLArchive;

/*! \brief base class for all objects

  Defines an unique identity number
*/
class PGLCORE_EXT_CLASS CPGLNode : public CObject
{
DECLARE_DYNCREATE(CPGLNode);
public:
	CPGLNode();	
	virtual ~CPGLNode();
	CPGLNode(const CPGLNode& n);

	bool CheckID( long tID ) const	{	return m_tID==tID;};
	long GetID() const				{	return m_tID;};

	void SetID( long tID )			{	m_tID = tID;};

	virtual void SerializeXML( CPGLArchive& ar );
private:
	long m_tID;
};
PGL_DECLARE_SMARTPTR(CPGLNode);

namespace pgl
{

class CObjectRegistrySingleton;
/*! \brief Object Registry class to store Runtime class information

	This class is a Destruction-Manager singleton

  \ingroup PGLGroup
*/
class CObjectRegistry
{
public:

	typedef std::map<std::_tstring, CPGLNodePtr (__cdecl *)(void)> CRegistry;

	//! \name Constructors
	//@{
	//! Initialize the Singleton object 
	CObjectRegistry();
	//! destroy the Singleton object 
	~CObjectRegistry();
	//@}
protected:
	friend class CObjectRegistrySingleton;

	//! \name Register methods
	//@{
	//! return type count
	size_t GetCountP() const				{	return m_registry.size();};
	//! adds a class
	void RegisterObjectP(LPCTSTR szName, CPGLNodePtr (*fcn)(void));
	//! return an object
	CPGLNodePtr GetObjectP(LPCTSTR szName);
	//@}
	CRegistry m_registry;
};

/*! \brief  Object factory map

 \ingroup PGLCoreSingletonGroup
*/
class PGLCORE_EXT_CLASS CObjectRegistrySingleton : public singletons::TSingleton<CObjectRegistry, 3>
{
public:
	static size_t GetCount();
	//! adds a class
	static void RegisterObject(LPCTSTR szName, CPGLNodePtr (*fcn)(void));
	//! return an object
	static CPGLNodePtr GetObject(LPCTSTR szName);
};

/*! \brief A dummy class to use CObjectRegistry.
	
	This class is used internally.
\ingroup PGLCoreSingletonGroup
*/
class CNodeRegisterer
{
public:
	CNodeRegisterer(LPCTSTR szName, CPGLNodePtr (*fcn)(void))
	{	CObjectRegistrySingleton::RegisterObject(szName, fcn);};
};

};

#endif // !defined(AFX_PGLOBJECTREGISTRY_H__3EE4CCAA_FDBF_4B8C_934F_B8A25A7DD905__INCLUDED_)
